package com.imstlife.vending.utils;

import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;

/**
 * Created by Feng on 2017/3/22.
 */

public class DeviceUtil {

    public static final int RK3188 = 0;
    public static final int RK3128 = 1;
    public static final int RK3288 = 2;
    public static final int Allwinner = 3;
    public static final int UnKnow = 4;


    static String TAG = "DeviceUtil";
    /**
     * 获取设备号
     * @param context
     * @return
     */
    public static String getDeviceId(Context context){
        String did = SharePersistentUtil.getSharePersistentString(context,"");

        if("".equals(did)){//未找到deviceId
            did =  Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
            if(did!=null&&did.length()>=14){
                did = did.substring(did.length()-14,did.length());
            }
            did = Long.parseLong(did, 16) + "";
            did =  did.substring(did.length() - 9,
                    did.length())  + "";
            SharePersistentUtil.saveSharePersistent(context, Cof.KEY_DEVICE_ID,did);
        }
        did = "619226432";
//        SharePersistentUtil.saveSharePersistent(context, Cof.KEY_DEVICE_ID,did);
        return  did;
    }

    /**
     * 设备类型, system/build.prop 中ro.product.model的值,由硬件厂商在固件中写死
     *
     * @return
     */
    public static int getDeviceType() {
        if (TextUtils.equals("rk3188", Build.MODEL)) {
            return RK3188;
        } else if (TextUtils.equals("hyperlcd-rk3288", Build.MODEL)) {
            return RK3288;
        } else if (TextUtils.equals("marvsmart", Build.MODEL)) {
            return RK3128;
        } else if (TextUtils.equals("Allwinner-Tablet", Build.MODEL)) {
            return Allwinner;
        } else {
            return UnKnow;
        }
    }

}
